package com.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mapper.NoticesMapper;
import com.model.Notices;
import com.util.PageBean;
@Service
public class NoticesServiceImpl implements NoticesService{
        
	@Autowired
	private NoticesMapper noticesMapper;

	//查询多条记录
	public List<Notices> queryNoticesList(Notices notices,PageBean page) throws Exception {
		Map<String, Object> map =getQueryMap(notices, page);
		
		List<Notices> getNotices = noticesMapper.query(map);
		
		return getNotices;
	}
	
	//得到记录总数
	@Override
	public int getCount(Notices notices) {
		Map<String, Object> map = getQueryMap(notices, null);
		int count = noticesMapper.getCount(map);
		return count;
	}
	
	private Map<String, Object> getQueryMap(Notices notices,PageBean page){
		Map<String, Object> map = new HashMap<String, Object>();
		if(notices!=null){
			map.put("plid", notices.getPlid());
			map.put("pltitle", notices.getPltitle());
			map.put("pldetail", notices.getPldetail());
			map.put("pldate", notices.getPldate());
			map.put("sort", notices.getSort());
			map.put("condition", notices.getCondition());

		}
		PageBean.setPageMap(map, page);
		return map;
	}
		
	//添加
	public int insertNotices(Notices notices) throws Exception {
		return noticesMapper.insertNotices(notices);
	}

	//根据ID删除
	public int deleteNotices(int id) throws Exception {
		return noticesMapper.deleteNotices(id);
	}

	//更新
	public int updateNotices(Notices notices) throws Exception {
		return noticesMapper.updateNotices(notices);
	}
	
	//根据ID得到对应的记录
	public Notices queryNoticesById(int id) throws Exception {
		Notices po =  noticesMapper.queryNoticesById(id);
		return po;
	}
}

